package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class Controller {
    @Autowired
    ServiceImpl service;
//    1.1流量分时统计（新访客数）测试
    //1.1流量分时统计折线图进行展示（新访客数）
    @RequestMapping("/show")
    public Object show(String nowDate){
        List<Map> show = service.show(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONObject dataobject = new JSONObject();


        JSONArray xArray = new JSONArray();
        for (Map map : show) {
           xArray.add(map.get("a"));
        }
        dataobject.put("categories",xArray);

        JSONArray yArray = new JSONArray();
        JSONObject yobject = new JSONObject();
        yobject.put("name","新用户");
        JSONArray dataArray = new JSONArray();
        for (Map map : show) {
            dataArray.add(map.get("b"));
        }
        yobject.put("data",dataArray);
        yArray.add(yobject);

        JSONObject yobject1 = new JSONObject();
        yobject1.put("name","新访客数");
        JSONArray ydata01 = new JSONArray();
        for (Map map : show) {
            ydata01.add(map.get("c"));
        }
        yobject1.put("data",ydata01);
        yArray.add(yobject1);
        dataobject.put("series",yArray);

        jsonObject.put("data",dataobject);

        return jsonObject;
    }
//1.2答题情况统计测试
//1.2答题情况统计轮播表格显示
@RequestMapping("/show1")
    public Object show1(String nowDate){
    List<Map> list = service.show1(nowDate);
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("status",0);
    jsonObject.put("msg","");

    JSONObject dataobject = new JSONObject();
    JSONArray xArray = new JSONArray();

    JSONObject jsonObject1 = new JSONObject();
    jsonObject1.put("name","编号");
    jsonObject1.put("id","subsys");
    xArray.add(jsonObject1);

    JSONObject jsonObject2 = new JSONObject();
    jsonObject2.put("name","题目");
    jsonObject2.put("id","module");
    xArray.add(jsonObject2);

    JSONObject jsonObject3 = new JSONObject();
    jsonObject3.put("name","正确答题次数");
    jsonObject3.put("id","business");
    xArray.add(jsonObject3);


    JSONObject jsonObject4 = new JSONObject();
    jsonObject4.put("name","答题次数");
    jsonObject4.put("id","name");
    xArray.add(jsonObject4);

    JSONObject jsonObject5 = new JSONObject();
    jsonObject5.put("name","正确率");
    jsonObject5.put("id","value");
    xArray.add(jsonObject5);

    dataobject.put("columns",xArray);

    JSONArray yArray = new JSONArray();
    for (Map map : list) {
        JSONObject jsonObject6 = new JSONObject();
        jsonObject6.put("subsys",map.get("a"));
        jsonObject6.put("module",map.get("b"));
        jsonObject6.put("business",map.get("c"));
        jsonObject6.put("name",map.get("d"));
        jsonObject6.put("value",map.get("e"));
        yArray.add(jsonObject6);

    }
    dataobject.put("rows",yArray);


    jsonObject.put("data",dataobject);


    return jsonObject;
}

//1.3各试卷考试统计测试
 // 1.3各试卷考试统计
@RequestMapping("/show2")
public Object show2(String nowDate){
    List<Map> list = service.show2(nowDate);
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("status",0);
    jsonObject.put("msg","");

    JSONObject dataobject = new JSONObject();
    JSONArray xArray = new JSONArray();

    JSONObject jsonObject1 = new JSONObject();
    jsonObject1.put("name","编号");
    jsonObject1.put("id","subsys");
    xArray.add(jsonObject1);

    JSONObject jsonObject2 = new JSONObject();
    jsonObject2.put("name","试卷");
    jsonObject2.put("id","module");
    xArray.add(jsonObject2);

    JSONObject jsonObject3 = new JSONObject();
    jsonObject3.put("name","考试人次");
    jsonObject3.put("id","business");
    xArray.add(jsonObject3);


    JSONObject jsonObject4 = new JSONObject();
    jsonObject4.put("name","平均分");
    jsonObject4.put("id","name");
    xArray.add(jsonObject4);

    JSONObject jsonObject5 = new JSONObject();
    jsonObject5.put("name","平均时长");
    jsonObject5.put("id","value");
    xArray.add(jsonObject5);

    dataobject.put("columns",xArray);

    JSONArray yArray = new JSONArray();
    for (Map map : list) {
        JSONObject jsonObject6 = new JSONObject();
        jsonObject6.put("subsys",map.get("a"));
        jsonObject6.put("module",map.get("b"));
        jsonObject6.put("business",map.get("c"));
        jsonObject6.put("name",map.get("d"));
        jsonObject6.put("value",map.get("e"));
        yArray.add(jsonObject6);

    }
    dataobject.put("rows",yArray);


    jsonObject.put("data",dataobject);


    return jsonObject;
}
//1.4各来源流量统计测试
    //1.4各来源流量统计
}
